package gitee_hook

import (
	"encoding/json"
	"fmt"
	"testing"
)

var pushData = `
{
    "after": "f0c2eb5df19ddd53392e645e50dc1213ca213457",
    "before": "6e05490b9d71d3214dc518e5bb6585a875e73253",
    "commits": [
        {
            "added": [
                "gitee/common.go",
                "gitee/issue_hook.go",
                "gitee/note_hook.go",
                "gitee/pull_request_hook.go",
                "gitee/push_hook.go",
                "gitee/utils.go",
                "go.mod",
                "test_tool/.gitignore",
                "test_tool/main.go"
            ],
            "author": {
                "email": "panleiming@waibaoxia.com",
                "id": null,
                "name": "panleiming",
                "remark": null,
                "time": "2022-03-13T13:57:06+08:00",
                "url": null,
                "user": null,
                "user_name": null,
                "username": null
            },
            "committer": {
                "email": "panleiming@waibaoxia.com",
                "id": null,
                "name": "panleiming",
                "remark": null,
                "time": null,
                "url": null,
                "user": null,
                "user_name": null,
                "username": null
            },
            "distinct": true,
            "id": "f0c2eb5df19ddd53392e645e50dc1213ca213457",
            "message": "define gitee webhook\n",
            "modified": [],
            "parent_ids": [
                "6e05490b9d71d3214dc518e5bb6585a875e73253"
            ],
            "removed": [],
            "timestamp": "2022-03-13T13:57:06+08:00",
            "tree_id": "aa664f0312127c9f00ed14f2ce77d009e26caee1",
            "url": "https://gitee.com/waibaoxia/webhook/commit/f0c2eb5df19ddd53392e645e50dc1213ca213457"
        }
    ],
    "commits_more_than_ten": false,
    "compare": "https://gitee.com/waibaoxia/webhook/compare/6e05490b9d71d3214dc518e5bb6585a875e73253...f0c2eb5df19ddd53392e645e50dc1213ca213457",
    "created": false,
    "deleted": false,
    "enterprise": null,
    "head_commit": {
        "added": [
            "gitee/common.go",
            "gitee/issue_hook.go",
            "gitee/note_hook.go",
            "gitee/pull_request_hook.go",
            "gitee/push_hook.go",
            "gitee/utils.go",
            "go.mod",
            "test_tool/.gitignore",
            "test_tool/main.go"
        ],
        "author": {
            "email": "panleiming@waibaoxia.com",
            "id": null,
            "name": "panleiming",
            "remark": null,
            "time": "2022-03-13T13:57:06+08:00",
            "url": null,
            "user": null,
            "user_name": null,
            "username": null
        },
        "committer": {
            "email": "panleiming@waibaoxia.com",
            "id": null,
            "name": "panleiming",
            "remark": null,
            "time": null,
            "url": null,
            "user": null,
            "user_name": null,
            "username": null
        },
        "distinct": true,
        "id": "f0c2eb5df19ddd53392e645e50dc1213ca213457",
        "message": "define gitee webhook\n",
        "modified": [],
        "parent_ids": [
            "6e05490b9d71d3214dc518e5bb6585a875e73253"
        ],
        "removed": [],
        "timestamp": "2022-03-13T13:57:06+08:00",
        "tree_id": "aa664f0312127c9f00ed14f2ce77d009e26caee1",
        "url": "https://gitee.com/waibaoxia/webhook/commit/f0c2eb5df19ddd53392e645e50dc1213ca213457"
    },
    "hook_id": 935886,
    "hook_name": "push_hooks",
    "hook_url": "https://gitee.com/waibaoxia/webhook/hooks/935886/edit",
    "password": "aaaaaaaaaaaaa",
    "project": {
        "clone_url": "https://gitee.com/waibaoxia/webhook.git",
        "created_at": "2022-03-13T10:35:59+08:00",
        "default_branch": "master",
        "description": "",
        "fork": false,
        "forks_count": 0,
        "full_name": "waibaoxia/webhook",
        "git_http_url": "https://gitee.com/waibaoxia/webhook.git",
        "git_ssh_url": "git@gitee.com:waibaoxia/webhook.git",
        "git_svn_url": "svn://gitee.com/waibaoxia/webhook",
        "git_url": "git://gitee.com/waibaoxia/webhook.git",
        "has_issues": true,
        "has_pages": false,
        "has_wiki": true,
        "homepage": null,
        "html_url": "https://gitee.com/waibaoxia/webhook",
        "id": 21383091,
        "language": "Go",
        "license": "GPL-3.0",
        "name": "webhook",
        "name_with_namespace": "潘雷明/webhook",
        "namespace": "waibaoxia",
        "open_issues_count": 0,
        "owner": {
            "avatar_url": "https://gitee.com/assets/no_portrait.png",
            "email": "10295679+waibaoxia@user.noreply.gitee.com",
            "html_url": "https://gitee.com/waibaoxia",
            "id": 10295679,
            "login": "waibaoxia",
            "name": "潘雷明",
            "remark": null,
            "site_admin": false,
            "type": "User",
            "url": "https://gitee.com/waibaoxia",
            "user_name": "waibaoxia",
            "username": "waibaoxia"
        },
        "path": "webhook",
        "path_with_namespace": "waibaoxia/webhook",
        "private": true,
        "pushed_at": "2022-03-13T13:57:11+08:00",
        "ssh_url": "git@gitee.com:waibaoxia/webhook.git",
        "stargazers_count": 0,
        "svn_url": "svn://gitee.com/waibaoxia/webhook",
        "updated_at": "2022-03-13T13:57:11+08:00",
        "url": "https://gitee.com/waibaoxia/webhook",
        "watchers_count": 1
    },
    "push_data": null,
    "pusher": {
        "email": "10295679+waibaoxia@user.noreply.gitee.com",
        "id": 10295679,
        "name": "潘雷明",
        "url": "https://gitee.com/waibaoxia",
        "user_name": "waibaoxia",
        "username": "waibaoxia"
    },
    "ref": "refs/heads/master",
    "repository": {
        "clone_url": "https://gitee.com/waibaoxia/webhook.git",
        "created_at": "2022-03-13T10:35:59+08:00",
        "default_branch": "master",
        "description": "",
        "fork": false,
        "forks_count": 0,
        "full_name": "waibaoxia/webhook",
        "git_http_url": "https://gitee.com/waibaoxia/webhook.git",
        "git_ssh_url": "git@gitee.com:waibaoxia/webhook.git",
        "git_svn_url": "svn://gitee.com/waibaoxia/webhook",
        "git_url": "git://gitee.com/waibaoxia/webhook.git",
        "has_issues": true,
        "has_pages": false,
        "has_wiki": true,
        "homepage": null,
        "html_url": "https://gitee.com/waibaoxia/webhook",
        "id": 21383091,
        "language": "Go",
        "license": "GPL-3.0",
        "name": "webhook",
        "name_with_namespace": "潘雷明/webhook",
        "namespace": "waibaoxia",
        "open_issues_count": 0,
        "owner": {
            "avatar_url": "https://gitee.com/assets/no_portrait.png",
            "email": "10295679+waibaoxia@user.noreply.gitee.com",
            "html_url": "https://gitee.com/waibaoxia",
            "id": 10295679,
            "login": "waibaoxia",
            "name": "潘雷明",
            "remark": null,
            "site_admin": false,
            "type": "User",
            "url": "https://gitee.com/waibaoxia",
            "user_name": "waibaoxia",
            "username": "waibaoxia"
        },
        "path": "webhook",
        "path_with_namespace": "waibaoxia/webhook",
        "private": true,
        "pushed_at": "2022-03-13T13:57:11+08:00",
        "ssh_url": "git@gitee.com:waibaoxia/webhook.git",
        "stargazers_count": 0,
        "svn_url": "svn://gitee.com/waibaoxia/webhook",
        "updated_at": "2022-03-13T13:57:11+08:00",
        "url": "https://gitee.com/waibaoxia/webhook",
        "watchers_count": 1
    },
    "sender": {
        "avatar_url": "https://gitee.com/assets/no_portrait.png",
        "email": "10295679+waibaoxia@user.noreply.gitee.com",
        "html_url": "https://gitee.com/waibaoxia",
        "id": 10295679,
        "login": "waibaoxia",
        "name": "潘雷明",
        "remark": null,
        "site_admin": false,
        "type": "User",
        "url": "https://gitee.com/waibaoxia",
        "user_name": "waibaoxia",
        "username": "waibaoxia"
    },
    "sign": "",
    "timestamp": "1647151031936",
    "total_commits_count": 1,
    "user": {
        "email": "10295679+waibaoxia@user.noreply.gitee.com",
        "id": 10295679,
        "name": "潘雷明",
        "url": "https://gitee.com/waibaoxia",
        "user_name": "waibaoxia",
        "username": "waibaoxia"
    },
    "user_id": 10295679,
    "user_name": "潘雷明"
}
`

func TestPushHook(t *testing.T) {
	pushHook := &PushHook{}
	err := json.Unmarshal([]byte(pushData), pushHook)
	if err != nil {
		t.Error(err)
		t.FailNow()
	}
	data, _ := json.MarshalIndent(pushHook, "  ", "  ")
	fmt.Println(string(data))
}
